package com.aloda.controller.admin;

import com.aloda.annotation.AdminAuthCheck;
import com.aloda.annotation.OperateLogAnno;
import com.aloda.dto.userToken.UserTokenAddDTO;
import com.aloda.dto.userToken.UserTokenEditDTO;
import com.aloda.query.UserTokenPageDTO;
import com.aloda.result.PageResult;
import com.aloda.result.Result;
import com.aloda.service.UserTokenService;
import com.aloda.vo.userToken.UserTokenPageVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户token controller
 */
@Slf4j
@RestController("token-admin")
@RequestMapping("/admin/token")
public class UserTokenController {

    @Resource
    private UserTokenService userTokenService;

    /**
     * 新增用户token
     * @param userTokenAddDTO
     * @return
     */
    @OperateLogAnno(category = "新增用户Token")
    @AdminAuthCheck
    @PostMapping
    public Result<Long> addUserToken(@RequestBody UserTokenAddDTO userTokenAddDTO) {
        return Result.success(userTokenService.addUserToken(userTokenAddDTO));
    }

    /**
     * 编辑用户token
     * @param userTokenEditDTO
     * @return
     */
    @OperateLogAnno(category = "编辑用户token")
    @AdminAuthCheck
    @PutMapping
    public Result<Long> editUserToken(@RequestBody UserTokenEditDTO userTokenEditDTO) {
        return Result.success(userTokenService.editUserToken(userTokenEditDTO));
    }

    /**
     * 分页查询
     * @param userTokenPageDTO
     * @return
     */
    @AdminAuthCheck
    @PostMapping("/page")
    public Result<PageResult<UserTokenPageVO>> pageQuery(@RequestBody UserTokenPageDTO userTokenPageDTO) {
        return Result.success(userTokenService.pageQuery(userTokenPageDTO));
    }

    /**
     * 删除用户token
     * @param ids
     * @return
     */
    @OperateLogAnno(category = "删除用户token")
    @AdminAuthCheck
    @DeleteMapping
    public Result<Boolean> deleteUserToken(@RequestBody List<Long> ids) {
        return Result.success(userTokenService.removeByIds(ids));
    }
}
